/**
 * 476. 数字的补数
 */
public class NumberComplement {

    public int Complement(int num){
        int n=0;
        for (int i = 0; i <=30 ; i++) {
            if(num>1<<i){
                n++;
            }else {
                break;
            }
        }
        int m=n==30?0x7fffffff:(1<<(n+1))-1;
        return num^m;
    }
}
